﻿
using LanqiQAwebapi.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Data;
using LanqiQAwebapi.Interface;

using LanqiQAwebapi.Todo;
using LanqiQAwebapi.Dto;
namespace LanqiQAwebapi.Controllers
{

    [ApiController]
    [Route("/[controller]")]
    [EnableCors("AllowCors")]
    public class LoginController : ControllerBase
    {

     
        private readonly ILogger<LoginController> _logger;
        private readonly IUserServer _userServer;
        public LoginController(ILogger<LoginController> logger, IUserServer userServer)
        {
            _logger= logger;
            _userServer= userServer;
        }
        [HttpPost("LoginByUser")]
        [EnableCors("AllowCors")]
        public JsonResult Login([FromBody] UserLoginByUser credentials)
        {
         return   new JsonResult(_userServer.UserLoginByUser(credentials));
        }


        [EnableCors("AllowCors")]
        [HttpPost("TestTaken")]
        [Authorize(Roles = "r_admin")]

        public JsonResult TestTaken(string test)
        {
            JsonResult s = new JsonResult(test);


            return s;
        }
    }

}
